package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.service.MenuService;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/menu")
public class MenuController {
    @Reference
    private MenuService menuService;
    /*
    * 根据用户赋予对应的菜单
    * */
    @RequestMapping("/findAll")
    public Result findAll(){
        //获取用户登录信息
        User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (user == null){
            return new Result(false, MessageConstant.GET_USERNAME_FAIL);
        }
        return menuService.findAll(user.getUsername());
    }

}
